home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 February
/
EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso
/
progs
/
editor
/
frexxed
/
fpl
/
tabconvert.fpl
< prev
next >
Wrap
Text File
|
1995-07-18
|
2KB
|
91 lines
void TabToSpace()
{
int id=GetEntryID();
int new=DuplicateEntry();
int stopline=1, startline=ReadInfo("lines");
if (new) {
int size, tabsize, bytepos, del, counter;
Visible(0);
if (ReadInfo("block_exist")) {
stopline=ReadInfo("block_begin_y");
startline=ReadInfo("block_end_y")-1;
}
if (startline>stopline) {
CurrentBuffer(new);
Status(id, "Tab converting.");
tabsize=ReadInfo("tab_size");
GotoLine(startline, ReadInfo("line_length", new, startline));
while (Search("\t", "f-")>=0 && ReadInfo("line")>=stopline) {
bytepos=ReadInfo("byte_position")-1;
size=0;
del=1;
while (bytepos>=0 && GetChar(bytepos)=='\t') {
bytepos--;
size+=tabsize;
del++;
CursorLeft();
}
size+=tabsize-((ReadInfo("column")-1)%tabsize);
Delete(del);
Output(sprintf(joinstr("%",ltostr(size), "lc"), ' '));
if (!(counter++&15))
Status(id, ltostr(ReadInfo("line")-stopline));
}
}
Kill(new);
CurrentBuffer(id);
Visible(1);
}
}
void SpaceToTab()
{
int id=GetEntryID();
int new=DuplicateEntry();
int stopline=1, startline=ReadInfo("lines");
if (new) {
int tabsize, bytepos, del, column, counter;
string output;
Visible(0);
if (ReadInfo("block_exist")) {
stopline=ReadInfo("block_begin_y");
startline=ReadInfo("block_end_y")-1;
}
CurrentBuffer(new);
Status(id, "Space converting.");
tabsize=ReadInfo("tab_size");
GotoLine(startline, ReadInfo("line_length", new, startline));
while (Search(" ", "f-")>=0 && ReadInfo("line")>=stopline) {
switch ((ReadInfo("column"))%tabsize) {
case tabsize-1:
bytepos=ReadInfo("byte_position")-1;
del=2;
output="\t";
while (bytepos>=0 && GetChar(bytepos)==' ') {
bytepos--;
if (!(del%tabsize))
output+="\t";
del++;
CursorLeft();
}
Delete(del);
Output(output);
if (!(counter++&15))
Status(id, ltostr(ReadInfo("line")-stopline));
break;
case 0:
CursorRight();
}
}
Kill(new);
CurrentBuffer(id);
Visible(1);
}
}
AssignKey("ExecuteFile(\"TabConvert.FPL\", \"TabToSpace();\");", "Amiga 'tab'");
AssignKey("ExecuteFile(\"TabConvert.FPL\", \"SpaceToTab();\");", "Amiga Shift 'tab'");